<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/9/24
  Time: 9:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>学生展示</title>
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" >

    <style type="text/css">
        .layui-table-cell{
            height:auto!important;
            white-space:normal;
        }
    </style>
</head>
<body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addStu">添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getData">获取当前页数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">是否全选</button>
    </div>
</script>
<form class="layui-form" action=""  id="saveUserForm" style="display: none"  lay-filter="updateUserFormFilter">
    <input type="hidden" name="id" id="id">

    <form class="layui-form" action="" >

        <div class="registerbox-title">用户回访中心</div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户</label>
            <div class="layui-input-inline">
                <input type="text" name="name" onblur="checkUsername(this)"  lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label">测试用户</label>
            <div class="layui-input-inline">
                <input type="text" name="tel"  lay-verify="required" placeholder="请输入手机号" autocomplete="off"
                       class="layui-input" id="tel">
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">邀请码</label>
            <div class="layui-input-inline">
                <input type="text" name="yqcode"  lay-verify="required" placeholder="请输入邀请码"
                       autocomplete="off" class="layui-input" id="yqcode">
            </div>
        </div>
        <div class="layui-form-item " >
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="recond"  lay-verify="required" placeholder=""
                       autocomplete="off" class="layui-input" id="recond">
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">回访内容</label>
            <div class="layui-input-inline">
                <input type="text" name="remark"  lay-verify="required" placeholder=""
                       autocomplete="off" class="layui-input" id="remark">
            </div>
        </div>





        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSaveUser">确认</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
</form>

<%----%>


<%--查询条件--%>
<form class="layui-form" action="">

    <div class="layui-inline">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="name" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" name="tel" placeholder="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">邀请码</label>
        <div class="layui-input-inline">
            <input type="text" name="yqcode" placeholder="请输入邀请码" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-inline">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<table class="layui-hide" id="test" lay-filter = "test"></table>
<!-- 注意：项目正式环境请勿引用该地址 -->
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-3.6.1.min.js"></script>
<script>
    $(function(){
        layui.use(['table','layer','form','jquery'], function(){
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery;
            var upload = layui.upload
                , element = layui.element;
            var namestatus=true;

            table.render({
                // element  元素
                elem: '#test'
                ,page:true
                ,limit:2
                ,limits:[2,4,6,8]
                ,toolbar: '#toolbarDemo'
                ,url:'${pageContext.request.contextPath}/tMhtSurvey/querySurvey' //  表格了里面所需要的数据就是一个list里面有很多的map、对象
                ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                // 传过来的数据进行处理  laydata
                // ,parseData: function (res) {
                //     return {
                //         "code":res.code,
                //         "msg":res.msg,
                //         "count": res.data.total,//从返回的json数据中取出总行数
                //         "data": res.data.list//返回的json数据有两层，layui不支持多层数据，所以是res.list
                //     }
                // }
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    // field 后面跟的内容  必须跟后台传过来的数据里面的map 的key保持一致
                    ,{field:'id', title: 'ID', sort: true}
                    ,{field:'rid', title: 'rid', sort: true}
                    ,{field:'name', title: '测试用户名', sort: true}
                    ,{field:'tel', title: '手机号', sort: true}
                    ,{field:'yqcode', title: '邀请码', sort: true}
                    ,{field:'recond', title: '备注', sort: true}
                    ,{field:'remark', title: '回访内容', sort: true}
                    ,{field:'username', title: '创建回访人'} //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增
                    ,{field:'updateby', title: '修改回访人', sort: true}
                    ,{field:'createtime', title: '创建时间', sort: true}
                    ,{field:'updatetime', title: '修改时间', sort:true}
                    ,{fixed: 'right', title:'操作', width: 125, minWidth: 125, toolbar: '#barDemo'}
                ]]

            });


            // 查询
            form.on('submit(formDemo)', function(data){
                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                table.reload('test', {
                    where: data.field,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });





            // 工具栏事件
            table.on('toolbar(test)', function(obj){
                var uid = obj.config.uid;
                var checkStatus = table.checkStatus(uid);
                var othis = lay(this);
                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(layui.util.escape(JSON.stringify(data)));
                        break;
                    case 'getData':
                        var getData = table.getData(id);
                        console.log(getData);
                        layer.alert(layui.util.escape(JSON.stringify(getData)));
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选': '未全选')
                        break;
                    case 'addStu':
                        $("#saveUserForm")[0].reset();
                        $(".pass").css("display","block");
                        $('#id').val(null)
                        layer.open({
                            type: 1,
                            area: ['500px', '400px'],
                            offset: '100px',
                            content:$("#saveUserForm"),
                            cancel: function(index, layero){

                                layer.close(index);
                                $("#saveUserForm").hide();
                                return false;
                            }
                        });
                        break;
                };
            });

            //触发单元格工具事件
            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'edit'){
                    $(".pass").css("display","none");
                    layer.open({
                        type: 1,
                        area: ['500px', '400px'],
                        offset: '100px',
                        content:$("#saveUserForm"),
                        cancel: function(index, layero){

                            layer.close(index);
                            $("#saveUserForm").hide();
                        }
                    });

                    form.val('updateUserFormFilter',data);


                }else if (obj.event === 'del'){
                    // alert(JSON.stringify(data.id))
                    if (confirm("确定要删除吗?")){
                        var shuzu={};
                        shuzu.id=data.id
                        $.ajax({
                            url:"${pageContext.request.contextPath}/tMhtSurvey/delSurvey",
                            type:"post",
                            dataType:"JSON",
                            data:shuzu,//表单里所有数据
                            success:function (ret){
                                // alert(JSON.stringify(ret))
                                if (ret.data==true){
                                    // alert("刷新")
                                    table.reload('test')
                                }

                            }
                        })
                    }


                }
            });



            //提交表单
            // Layui提交表单 监听提交  data代表的是form表单里面的所有的内容
            form.on('submit(formSaveUser)', function(data){
                if(namestatus){
                    // alert(JSON.stringify(data))
                    $.ajax({
                        url:"${pageContext.request.contextPath}/tMhtSurvey/updSurvey",
                        type:"post",
                        dataType:"JSON",
                        data:data.field,//表单里所有数据
                        success:function (ret){
                            if (ret.data == true){
                                //关闭所有弹框
                                layer.closeAll();
                                $("#saveUserForm").hide();
                                //刷新页面
                                table.reload('test');
                            }
                        }
                    })
                }
                return false;
            });
          });
        });











</script>

</body>
</html>
